
import java.io.IOException;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.ToneControl;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Karthik T
 */
public class audio {
    static Player paddle;
    static Player lost;
    static boolean mode = false;

    public audio(boolean mode){
        try {
            lost = Manager.createPlayer(getClass().getResourceAsStream("/GameOver.wav"), "audio/X-wav");
            paddle = Manager.createPlayer(getClass().getResourceAsStream("/PongBlip.wav"), "audio/X-wav");
            setMode(mode);
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (MediaException ex) {
            ex.printStackTrace();
        }
    }
    
    public audio() {
    	try {
            lost = Manager.createPlayer(getClass().getResourceAsStream("/GameOver.wav"), "audio/X-wav");
            paddle = Manager.createPlayer(getClass().getResourceAsStream("/PongBlip.wav"), "audio/X-wav");
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (MediaException ex) {
            ex.printStackTrace();
        }
    }

    public static void tone(){
        if(mode)
        try {
        // play a tone for 4000 milliseconds at volume 100
        Manager.playTone(ToneControl.C4, 4000, 100);
        }
        catch(MediaException me) {
        }
    }
    
    public static void paddle(){
        if(mode)
        try {
            paddle.start();
        } catch (MediaException ex) {
            ex.printStackTrace();
        }
    }
    //TODO slightly shorter sound for game over
    public static void lost(){
        if(mode)
        try {
            lost.start();
        } catch (MediaException ex) {
            ex.printStackTrace();
        }        
    }

    public void setMode(boolean mode) {
        audio.mode=mode;
    }
}
